<template>
    <div class="container">
        <div class="main">
            <div class="img">
                <el-carousel>
                    <el-carousel-item v-for="item in 4" :key="item">
                        <div class="img-item">
                            广告位招租
                        </div>
                    </el-carousel-item>
                </el-carousel>
            </div>

            <div class="page">
                <div class="title">
                    登录
                </div>

                <div>
                    <el-input v-model="username" placeholder="请输入用户名"></el-input>
                </div>

                <div>
                    <el-input v-model="password" type="password" placeholder="请输入密码"></el-input>
                </div>

                <div>
                    <el-button type="primary" @click="login">登录</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {request} from '../axios/request'
export default {
    data() {
        return {
            username: '',
            password: ''
        }
    },

    methods: {
        login() {
            request(
                'get',
                'user/login',
                {
                    username: this.username,
                    password: this.password
                }
            ).then(res => {
                if (res.code === 0) {
                    localStorage.setItem('token', res.token)
                    localStorage.setItem('username', res.user_name)

                    this.$message.success('登录成功')
                    this.$router.push('/')
                } else {
                    this.$message.error(res.msg)
                }
            })
        }
    },
}
</script>

<style lang="scss" scoped>
// div{
//     border: 1px solid;
// }
.container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
}

.main {
    width: 70%;
    height: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;

    margin-top: 12%;
    margin-bottom: 8%;

    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

    .img{
        flex-grow: 0.6;

        .el-carousel{
            height: 100%;
            width: 100%;
        }

        .el-carousel__item{
            height: 100%;
            width: 100%;

            display: flex;

            .img-item{
                height: 100%;
                width: 100%;
                background-color: gray;

                line-height: 300px;
            }
        }
    }

    .page{
        flex-grow: 0.4;
        display: flex;
        flex-direction: column;

        .title{
            height: 80px;
            line-height: 80px;
            font-size: 1.5rem;
            font-weight: bold;
            text-align: center;

            margin-top: 10px;
        }

        .el-input{
            margin-top: 8px;
            margin-bottom: 8px;

            width: 50% !important;
        }

        .el-button{
            margin-top: 20px;
            width: 50% !important;
        }
        
    }
}
</style>